package com.kyc.kycxkplaygame.activity.base;

import android.Manifest;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import com.kyc.kycxkplaygame.dbutils.IntImp.AlasbusyIApi;
import com.kyc.kycxkplaygame.dbutils.inter.HttpQuestResultListener;
import com.tbruyelle.rxpermissions.RxPermissions;
import rx.functions.Action1;

/**
 * Created by Administrator on 2018/8/24.
 */

public abstract class BaseFragment extends Fragment implements HttpQuestResultListener {

    public AlasbusyIApi propertyManagerApi;
    private ImageView back;
    private TextView title_txt;
    private ImageView title_img;
    private TextView title_imgtxt;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        //View inflate = View.inflate(getContext(), getLayout(), null);
        View view = inflater.inflate(getLayout(), container, false);

        RxPermissions rxPermissions = new RxPermissions(getActivity());
        rxPermissions.request(
                Manifest.permission.ACCESS_COARSE_LOCATION,
                Manifest.permission.RECORD_AUDIO,
                Manifest.permission.CALL_PHONE,
                Manifest.permission.INTERNET,
                Manifest.permission.ACCESS_COARSE_LOCATION,
                Manifest.permission.READ_EXTERNAL_STORAGE,
                Manifest.permission.WRITE_EXTERNAL_STORAGE,
                Manifest.permission.READ_PHONE_STATE)
                .subscribe(new Action1<Boolean>() {
                    @Override
                    public void call(Boolean granted) {
                        if (granted) {
                        } else {
                        }
                    }
                });


        propertyManagerApi = AlasbusyIApi.getInstance(getContext());
        propertyManagerApi.setHttpQuestResultListener(this);

        initView(view);
        initData();
        initListener();
        return view;
    }

    /*public void getTitleLayout(View view) {
        back = view.findViewById(R.id.title_back);
        title_txt = view.findViewById(R.id.title_txt);
        title_img = view.findViewById(R.id.title_img);
        title_imgtxt = view.findViewById(R.id.title_imgtxt);
    }

    public void back(boolean istrue){
        if(istrue) {
            back.setVisibility(View.VISIBLE);
            back.setEnabled(true);
            back.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    getActivity().finish();
                }
            });
        }else {
            back.setVisibility(View.INVISIBLE);
            back.setEnabled(false);
        }
    }

    public void setTitletxt(String str){
        title_txt.setText(str);
    }

    public void setTitleImg(boolean istrue,int resid){
        if(istrue) {
            title_img.setVisibility(View.VISIBLE);
            title_img.setImageResource(resid);
            title_img.setEnabled(true);
            title_img.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    getMakeMethod();
                }
            });
        }else {
            title_img.setVisibility(View.INVISIBLE);
            title_img.setEnabled(false);
        }
    }

    public void setimgTxt(boolean istrue,String str){
        if(istrue) {
            title_imgtxt.setVisibility(View.VISIBLE);
            title_imgtxt.setEnabled(true);
            title_imgtxt.setText(str);
            title_imgtxt.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    getMakeMethod();
                }
            });
        }else {
            title_imgtxt.setVisibility(View.GONE);
            title_imgtxt.setEnabled(false);
        }
    }

    public void getMakeMethod() {

    }
*/
    protected abstract void initView(View view);

    protected abstract void initData();

    protected abstract void initListener();

    public abstract int getLayout();

    @Override
    public void onError(Object e) {

    }

    @Override
    public void onSuccess(Object object) {
        getSuccess(object);
    }

    @Override
    public void onQuestErroCode(Object object) {

    }

    protected abstract void getSuccess(Object object);

    /*@Override
    public Resources getResources() {
        Resources res = super.getResources();
        Configuration config=new Configuration();
        config.setToDefaults();
        res.updateConfiguration(config,res.getDisplayMetrics() );
        return res;
    }*/

}
